package com.learn.atomic;

import java.util.concurrent.atomic.AtomicMarkableReference;

/**
 * @author ln
 * @Description: ${todo}
 * @date 2020/12/21
 */
public class TestAtomicMarkableReference {

    public static void main(String[] args) {
        GarbageBag bag = new GarbageBag("装满了垃圾");

//        参数2 mark可以看作一个标记，标识垃圾袋装满了
        AtomicMarkableReference<GarbageBag> ref = new AtomicMarkableReference<GarbageBag>(bag, true);

        GarbageBag prev = ref.getReference();

        boolean result = ref.compareAndSet(prev, new GarbageBag("空垃圾袋"), true, false);


    }

}

class GarbageBag{
    String desc;

    public GarbageBag(String desc) {
        this.desc = desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }
}
